package team.gzjmzy.web.controller;

import java.util.List;
import java.util.Arrays;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.gzjmzy.common.annotation.Log;
import team.gzjmzy.common.core.controller.BaseController;
import team.gzjmzy.common.core.domain.AjaxResult;
import team.gzjmzy.common.enums.BusinessType;
import team.gzjmzy.system.domain.entity.TReturnInfo;
import team.gzjmzy.system.service.ITReturnInfoService;
import team.gzjmzy.common.utils.poi.ExcelUtil;
import team.gzjmzy.common.core.page.TableDataInfo;

/**
 * 借阅记录Controller
 * 
 * @author gzjmzy
 * @date 2021-08-05
 */
@RestController
@RequestMapping("/system/info")
public class TReturnInfoController extends BaseController {

    @Autowired
    private ITReturnInfoService iTReturnInfoService;

    /**
     * 查询借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
        public TableDataInfo list(TReturnInfo tReturnInfo) {
        startPage();
        List<TReturnInfo> list = iTReturnInfoService.queryList(tReturnInfo);
        return getDataTable(list);
    }
    
    /**
     * 获取借阅记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(iTReturnInfoService.queryById(id));
    }

    /**
     * 新增借阅记录
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')" )
    @Log(title = "新增借阅记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TReturnInfo tReturnInfo) {
        return toAjax(iTReturnInfoService.add(tReturnInfo));
    }

    /**
     * 修改借阅记录
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')" )
    @Log(title = "修改借阅记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TReturnInfo tReturnInfo) {
        return toAjax(iTReturnInfoService.edit(tReturnInfo));
    }

                                                                                                                                                    
    /**
     * 删除借阅记录
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')" )
    @Log(title = "删除借阅记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(iTReturnInfoService.delByIds(Arrays.asList(ids)));
    }

    /**
     * 导出借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')" )
    @Log(title = "导出借阅记录列表" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TReturnInfo tReturnInfo) {
        List<TReturnInfo> list = iTReturnInfoService.queryList(tReturnInfo);
        ExcelUtil<TReturnInfo> util = new ExcelUtil<TReturnInfo>(TReturnInfo.class);
        return util.exportExcel(list, "info" );
    }
}
